<?php
class ChallengeOrderInfoVo extends SzAbstractMySqlVo
{

    private $userId;
    private $target;
    private $reward;
    private $createTime;

    /**
     * Initialize ChallengeOrderInfoVo.
     *
     * @param $userId
     * @param $target
     * @param $reward
     * @param $createTime
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return ChallengeOrderInfoVo
     */
    public function __construct($userId, $target, $reward, $createTime, $isInsert = false) {
        $this->userId = $userId;
        $this->target = json_decode($target, true);
        $this->reward = json_decode($reward, true);
        $this->createTime = $createTime;

        $this->isInsert = $isInsert;
        $this->voClassName = 'ChallengeOrderInfoVo';
        $this->ormName = 'ChallengeOrderInfo';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'target' => ($needEncode) ? $this->getTarget() : $this->getRawTarget(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
            'createTime' => $this->getCreateTime(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'target' => ($needEncode) ? $this->getTarget() : $this->getRawTarget(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
            'createTime' => $this->getCreateTime(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getTarget(),
            $this->getReward(),
            $this->getCreateTime(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getTarget()
    {
        return json_encode($this->target);
    }

    public function getRawTarget()
    {
        return $this->target;
    }

    public function setTarget($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 12800) {
            SzLogger::get()->error('[ChallengeOrderInfoVo] The length of column target exceed the limit, length / limit: ' . $encodedLength . ' / 12800');
            throw new SzException(10522, array('ChallengeOrderInfoVo', '12800', $encodedLength));
        } else if ($encodedLength > 11520) {
            SzLogger::get()->warn('[ChallengeOrderInfoVo] The length of column target exceed the warning level, length / limit: ' . $encodedLength . ' / 12800');
        }
        $this->saveColumnStatus(1, $this->target);
        $this->target = $val;
    }

    public function getReward()
    {
        return json_encode($this->reward);
    }

    public function getRawReward()
    {
        return $this->reward;
    }

    public function setReward($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 12800) {
            SzLogger::get()->error('[ChallengeOrderInfoVo] The length of column reward exceed the limit, length / limit: ' . $encodedLength . ' / 12800');
            throw new SzException(10522, array('ChallengeOrderInfoVo', '12800', $encodedLength));
        } else if ($encodedLength > 11520) {
            SzLogger::get()->warn('[ChallengeOrderInfoVo] The length of column reward exceed the warning level, length / limit: ' . $encodedLength . ' / 12800');
        }
        $this->saveColumnStatus(2, $this->reward);
        $this->reward = $val;
    }

    public function getCreateTime()
    {
        return $this->createTime;
    }

    public function setCreateTime($val)
    {
        $this->saveColumnStatus(3, $this->createTime);
        $this->createTime = $val;
    }

}